'use strict';
exports.main = async (event, context) => {
	const SECRET = '4c9b446f9dc58fc009b2a5e13b985032'
	const APPID = 'wxf9a6e81004d5a574'
	const appid_url =
		'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='+ APPID +'&secret=' + SECRET
	const access_token_res = await uniCloud.httpclient.request(appid_url, {
		method: 'GET',
		contentType: 'json', // 指定以application/json发送data内的数据
		dataType: 'json' // 指定返回值为json格式，自动进行parse
	})
	const access_token = access_token_res.data.access_token;
	const news_url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' + access_token
	var res = await uniCloud.httpclient.request(news_url, {
		method:'POST',
		data: {
			"scene": event._id,
		},
		contentType: "json"
	})
	// return res.data
	uniCloud.uploadFile({
	        cloudPath: event.title + 'QRCode' + '.jpg',
	        fileContent: res.data
	    })
		.then( res => {
			console.log(res)
		})
		.catch(err => {
			console.log(err)
		})
	
};
